<template>
  <Row type="flex">
    <Col flex="400px"> <h2 class="title2">年度信用评价结果 <i>{{ config.page.total }}</i></h2></Col>
    <Col flex="750px">
<!--   <Row :gutter="[12, 8]">
        <Col :span="6">
          <Select v-model:value="config.params.evalYear">
            <Option value="">全部评价年度</Option>
            <Option :value="item.id" v-for="item in dictionary.dateArr()">{{ item.dataValue }}</Option>
          </Select>
        </Col>
        <Col :span="7">

          <Select v-model:value="config.params.evalRet">
            <Option value="">全部评价结果</Option>
            <Option :value="item.id" v-for="item in dictionary.evalRet">{{ item.dataValue }}</Option>
          </Select>
        </Col>
        <Col :span="8">
          <Select v-model:value="config.params.type">
            <Option value="">全部工程类别</Option>
            <Option :value="item.id" v-for="item in dictionary.type">{{ item.dataValue }}</Option>
          </Select>
        </Col>
        <Col :span="3" class="text-right">
          <Button type="primary" @click="changeHandler({current: 1}, config)">查询</Button>
        </Col>
      </Row>-->
    </Col>
  </Row>

  <Table
      :columns="config.columns"
      :row-key="record => record.scoreId"
      :data-source="config.list"
      :pagination="config.page"
      :loading="config.loading"
      @change="(pagination)=> changeHandler(pagination, config)"
      bordered
  >
    <template #indexSlot="{ index }">{{(config.page.current-1)*10+index+1}}</template>
  </Table>
</template>

<script lang="ts">
import {defineComponent, inject, onMounted, reactive, ref, toRefs} from 'vue';
import {Row, Col, Table, Input, Select, Button, Modal, Descriptions,} from 'ant-design-vue';
import { getCorpCreditScoreApi , getIndexCodeApi } from '/@/api/company';
import { parseTime } from '/@/utils';
enum creditLevelEnum {
  APP_XYPJ_XYDJ_0001 = 'AAA',
  APP_XYPJ_XYDJ_0002 = 'AA',
  APP_XYPJ_XYDJ_0003 = 'A',
  APP_XYPJ_XYDJ_0004 = 'B',
  APP_XYPJ_XYDJ_0005 = 'C'
}
const columns = [
  { title: '序号', dataIndex: 'index', width: 70, align: 'center', slots: ({ customRender: 'indexSlot' }) },
  { title: '类别', dataIndex: 'objectRoleType',width: 300,},
  { title: '评价年度', dataIndex: 'scoreYear', width: 120 },
  { title: '评价结果', dataIndex: 'creditGrade' ,width: 200, customRender:({text})=> creditLevelEnum[text]},
  { title: '评价日期', dataIndex: 'scoreDate', customRender: ({ record })=> parseTime(record.scoreDate)},
]

export default defineComponent({
  components: {
    Table , Row, Col, Input, Button, Select, Option: Select.Option,
    Modal,Descriptions,DescriptionsItem:Descriptions.Item,
  },
  setup() {
    const corpId = inject('corpId') as string;
    const visible = ref<boolean>(false);
    const recordDetail = ref<any>()
    const dictionary = reactive({
      type:[],
      evalRet:[{
        id:'APP_XYPJ_XYDJ_0001',
        dataValue:'AAA'
      },{
        id:'APP_XYPJ_XYDJ_0002',
        dataValue:'AA'
      },{
        id:'APP_XYPJ_XYDJ_0003',
        dataValue:'A'
      },{
        id:'APP_XYPJ_XYDJ_0004',
        dataValue:'B'
      },{
        id:'APP_XYPJ_XYDJ_0005',
        dataValue:'C'
      }],
      dateArr:()=>{
        const date=new Date;
        const y = date.getFullYear()
        let dateArr:any = [];
        for (let i= 0;i<20;i++){
          dateArr.push({id:y-i,dataValue:(y-i)+'年'})
        }
        return dateArr;
      }
    })

    const config = reactive({
      columns: columns,
      list: [],
      loading: false,
      page: {
        total: 0,
        current: 1
      },
      params:{
        type:'',
        evalRet:'',
        evalYear:''
      }
    })


    const changeHandler = (pagination, config) => {
      const { current } = pagination;
      let { loading, list, page } = toRefs(config);
      let { type , evalRet , evalYear } = config.params;
      loading.value = true;
      getCorpCreditScoreApi( { corpId, current , type , evalRet , evalYear}).then( data => {
        let { records, current, total } = data;
        list.value = records;
        loading.value = false;
        page.value = {current, total};
      })
    }

    const getIndexCode = (data,back) =>{
      getIndexCodeApi(data).then(res=>{
        if(back)back(res)
      })
    }



    const init = () => {
      changeHandler({current: 1}, config);
      getIndexCode('APP_XYPJ_TYPE',function (res){   //初始化 字典表
        dictionary.type = res;
      })
    }

    onMounted(init)

    return {
      config, changeHandler , dictionary ,visible ,recordDetail , parseTime,creditLevelEnum
    }
  },
})
</script>

<style lang="less" scoped>

.ant-col{
  padding-top: 16px;
  margin-bottom: 8px;
}

.ant-select ,.ant-btn{
  width: 100%;
}

.ant-col.text-right{
  padding-right: 0 !important;
}

</style>
